package com.v1nsai.dataoff;

import java.util.Timer;
import java.util.TimerTask;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.wifi.WifiManager;
import android.os.Handler;

public class ScreenOff extends BroadcastReceiver{
	
	public void onReceive(Context context, Intent intent) {
		//declarations and initializations
		final WifiManager wm = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
		final Handler handler = new Handler();
		SharedPreferences prefs = context.getSharedPreferences(Settings.PREFS_NAME, 0);
		Timer t = new Timer();
		
		//turn off wifi after delay set in prefs
		if (prefs.getBoolean(Settings.WIFI_KILL, false) == true )
		{
			t.schedule(new TimerTask() {
				public void run() {
					handler.post( new Runnable() {
						public void run() {
							if(wm.isWifiEnabled() == true)
								wm.setWifiEnabled(false);
						}
					});
				}
			}, prefs.getInt(Settings.WIFI_OFFDELAY, 0) * 1000);
		}
		
		
	}
}


